home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / graphics / library / wgt51_r2.zip / WGT5 / EXAMPLES / WGT09.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-03  |  2.2 KB  |  71 lines

  1. /*
  2. ==============================================================================
  3.               WordUp Graphics Toolkit Version 5.0
  4.                  Demonstration Program 9                          
  5.                                           
  6.   Shows how the block functions work.
  7.                                           
  8.   *** PROJECT ***                                 
  9.   This program requires the file WGT5_WC.LIB to be linked.                    
  10.                                           
  11.   *** DATA FILES ***                                                          
  12.   NONE                                                                        
  13.                                WATCOM C++ VERSION 
  14. ==============================================================================
  15. */
  16.  
  17. #include <wgt5.h>
  18.  
  19.  
  20. void main(void)
  21. {
  22.   short i, x, y;
  23.   short oldmode;
  24.   color palette[256];
  25.   block screen1;                  // a full screen
  26.   block part1;                    // part of the screen
  27.  
  28.   printf ("WGT Example #9\n\n");
  29.   printf ("This program will use wnewblock to grab a bitmap from the screen.\n");
  30.   printf ("A small bitmap will be randomly pasted onto the screen until you press\n");
  31.   printf ("a key. The original screen is then restored. Press a key to end the program.\n");
  32.   printf ("\n\nPress any key to continue.\n");
  33.   getch ();
  34.  
  35.   if ( !vgadetected () )
  36.   {
  37.     printf("Error - VGA card required for any WGT program.\n");
  38.     exit (0);
  39.   }
  40.   oldmode = wgetmode ();
  41.   vga256 ();
  42.  
  43.   for (i = 1; i < 200; i++)
  44.   {
  45.     wsetcolor (i);
  46.     wline (0, 0, 319, i);
  47.     wline (319, 199, 0, 199-i);
  48.   }
  49.  
  50.   screen1 = wnewblock (0, 0, 319, 199);     /* capture the entire screen */
  51.   part1 = wnewblock (0, 0, 150, 150);       /* get a part of the screen */
  52.   /* Note that wnewblock allocates the memory for the block */
  53.  
  54.   wcls (0);
  55.  
  56.   do {
  57.     x = rand() % 320;
  58.     y = rand() % 200;
  59.     wputblock (x, y, part1, 0);             /* put the part somewhere */
  60.   } while (!kbhit ());
  61.  
  62.   getch ();
  63.   wputblock (0, 0, screen1, 0);             /* replace the mess with the */
  64.                         /* original screen */
  65.   getch ();                                 /* get the key */
  66.   wfreeblock (screen1);     /* *** make sure to free the memory! */
  67.   wfreeblock (part1);
  68.  
  69.   wsetmode (oldmode);
  70. }
  71.